package bildcommentsystem.pages;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;

public class Guess {
	
	@Property
	@Persist
	private int target, guessCount;
	
	@Property
	@Persist
	private String message;

	@Property
	private int current;

	@InjectPage
	private GameOver gameover;
	
	void setup(int target) {
		this.target = target;
		guessCount = 1;
	}

	Object onActionFromMakeGuess(int guess) {

		if (this.target == guess) {
			gameover.setup(this.target, guessCount);
			
			this.target = 0;
			this.guessCount = 0;
			guess = 0;
			
			return gameover;
		}

	    if (guess < this.target)
	        message = String.format("%d is too low.", guess);
	      else
	        message = String.format("%d is too high.", guess);		

		guessCount++;
		guess = 0;
		return null;

	}

}